import React from 'react';
import Components from 'Components';
import PageTemplates from 'PageTemplates';
import DvaIndex from "DvaCommon";
import Controls from 'Controls';
import * as UtilsCommon from 'UtilsCommon';
import { EnvConfig } from 'Configs';

const { a2dmah5 } = window;

const get = (namespace, className) => {
    if (namespace === 'UtilsCommon') return UtilsCommon[className];
    else if (namespace === 'Controls') return Controls[className];
    else if (namespace === 'Components') return Components[className];
    else if (namespace === 'Configs' && className === 'EnvConfig') return EnvConfig;
    else if (namespace === 'React' && className === 'React') return React;

    return null;
};

const getComponent = (type) => {
    const component = a2dmah5.getComponent(type);
    return component ? component(React, Components, get) : null;
};

const getPages = () => {
    return a2dmah5.getPages(PageTemplates, get);
};

const getModels = () => {
    return a2dmah5.getModels(DvaIndex);
};

const getExpandDataActions = (className) => {
    return a2dmah5.getExpandDataActions(className, get);
};

const getExpandEventActions = (className) => {
    return a2dmah5.getExpandEventActions(className, get);
};

const useExpandPageAction = a2dmah5.useExpandPageAction(React, get);

export default {
    getComponent,
    getModels,
    getPages,
    useExpandPageAction,
    getExpandDataActions,
    getExpandEventActions
};